import {useAppStore} from '@/store/app'
import { storeToRefs } from 'pinia';
import dayjs from "dayjs";
// 设置系统缩放比，适配各分辨率
export function refreshScale() {
  /*let baseWidth = document.documentElement.clientWidth;
  let baseHeight = document.documentElement.clientHeight;
  let MaxHeight = 1080
  const mainStore=useMainStore()
  mainStore.zoomRatio = baseHeight / MaxHeight
  */

  let baseWidth = document.documentElement.clientWidth;
  let baseHeight = document.documentElement.clientHeight;
  let appStyle = document.getElementById('app').style;
  let realRatio = baseWidth / baseHeight
  let designRatio = 16 / 9
  let scaleRate = baseWidth / 1920
  // if(realRatio>designRatio){
  scaleRate = baseHeight / 1080
  // }
  appStyle.transformOrigin = 'left top';
  appStyle.transform = `scale(${scaleRate}) translateX(-50%)`;
  appStyle.width = `${baseWidth / scaleRate}px`
}

// 设置系统缩放比，适配各分辨率
export function refreshZoomRatio() {
  let baseWidth = document.documentElement.clientWidth;
  let baseHeight = document.documentElement.clientHeight;
  let MaxHeight = 1080
  let MaxWidth = 1920
  let zoomRatio = baseHeight / MaxHeight
  let zoomRatioW = baseWidth / MaxWidth

  let appStore = useAppStore()
  if(zoomRatioW>=1){
    appStore.changeZoomRatioCenter('center')
  }else{
    appStore.changeZoomRatioCenter('0 0')
  }
  appStore.changeZoomRatio(zoomRatio)
  appStore.changeZoomRatioW(zoomRatioW)
}


export function callBacks(...cbs) {
  cbs.forEach(
    cb =>{
      return cb()
    }
  )
}
export function deepClone(source) {
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments', 'deepClone')
  }
  const targetObj = source.constructor === Array ? [] : {}
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}

export let isEmptyObj = (obj) => {
  let emptyObj = false
  if(!obj){
    return true
  }
  if(Object.keys(obj).length == 0){
    emptyObj = true   // true
  }else{
    emptyObj = false
  }

  return emptyObj
}

export let isArray = (arr) =>{
  let res = false;
  if(Object.prototype.toString.call(arr) === '[object Array]'){
    res = true
  }else{
    res = false
  }

  return res
}

export let isString = (str) =>{
  let res = false;
  if(Object.prototype.toString.call(str) === '[object String]'){
    res = true
  }else{
    res = false
  }

  return res
}

export let isNumber = (str) =>{
  let res = false;
  if(Object.prototype.toString.call(str) === '[object Number]'){
    res = true
  }else{
    res = false
  }

  return res
}

export let getWidthPx = (str) =>{
  let res = parseInt(str/1920 * window.innerWidth)
  return res
}
